package org.openit.portail.model;

import java.io.Serializable;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.proxy.HibernateProxy;
import org.springframework.format.annotation.DateTimeFormat;


/** 
 * Object mapping for hibernate-handled table: modele_paiement.
 * @author autogenerated
 */

@Entity
@Table(name = "modele_paiement", catalog = "portail")
public class ModelePaiement implements Cloneable, Serializable {

	/** Serial Version UID. */
	private static final long serialVersionUID = -559010018L;

	/** Use a WeakHashMap so entries will be garbage collected once all entities 
		referring to a saved hash are garbage collected themselves. */
	private static final Map<Serializable, Integer> SAVED_HASHES =
		Collections.synchronizedMap(new WeakHashMap<Serializable, Integer>());
	
	/** hashCode temporary storage. */
	private volatile Integer hashCode;
	

	/** Field mapping. */
	@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
	private Date dateDebut;
	/** Field mapping. */
	@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
	private Date dateFin;
	/** Field mapping. */
	private String description;
	/** Field mapping. */
	private Date dtCreation;
	/** Field mapping. */
	private Date dtModification;
	/** Field mapping. */
	private Integer id = 0; // init for hibernate bug workaround
	/** Field mapping. */
	private UserSystem idCreationUser;
	/** Field mapping. */
	private UserSystem idModificationUser;
	/** Field mapping. */
	private Service idService;
	/** Field mapping. */
	private Set<ModeleParametre> modeleParametre = new HashSet<ModeleParametre>();
	/** Field mapping. */
	private String nom;
	/** Field mapping. */
	private Double prix;
	/** Field mapping. */
	private Double tva;
	/**
	 * Default constructor, mainly for hibernate use.
	 */
	public ModelePaiement() {
		// Default constructor
	} 

	/** Constructor taking a given ID.
	 * @param id to set
	 */
	public ModelePaiement(Integer id) {
		this.id = id;
	}
	
 


 
	/** Return the type of this class. Useful for when dealing with proxies.
	* @return Defining class.
	*/
	@Transient
	public Class<?> getClassType() {
		return ModelePaiement.class;
	}
 

    /**
     * Return the value associated with the column: dateDebut.
	 * @return A Date object (this.dateDebut)
	 */
	@Column( name = "date_debut"  )
	public Date getDateDebut() {
		return this.dateDebut;
		
	}
	

  
    /**  
     * Set the value related to the column: dateDebut.
	 * @param dateDebut the dateDebut value you wish to set
	 */
	public void setDateDebut(final Date dateDebut) {
		this.dateDebut = dateDebut;
	}

    /**
     * Return the value associated with the column: dateFin.
	 * @return A Date object (this.dateFin)
	 */
	@Column( name = "date_fin"  )
	public Date getDateFin() {
		return this.dateFin;
		
	}
	

  
    /**  
     * Set the value related to the column: dateFin.
	 * @param dateFin the dateFin value you wish to set
	 */
	public void setDateFin(final Date dateFin) {
		this.dateFin = dateFin;
	}

    /**
     * Return the value associated with the column: description.
	 * @return A String object (this.description)
	 */
	@Column( length = 100  )
	public String getDescription() {
		return this.description;
		
	}
	

  
    /**  
     * Set the value related to the column: description.
	 * @param description the description value you wish to set
	 */
	public void setDescription(final String description) {
		this.description = description;
	}

    /**
     * Return the value associated with the column: dtCreation.
	 * @return A Date object (this.dtCreation)
	 */
	@Column( name = "dt_creation"  )
	public Date getDtCreation() {
		return this.dtCreation;
		
	}
	

  
    /**  
     * Set the value related to the column: dtCreation.
	 * @param dtCreation the dtCreation value you wish to set
	 */
	public void setDtCreation(final Date dtCreation) {
		this.dtCreation = dtCreation;
	}

    /**
     * Return the value associated with the column: dtModification.
	 * @return A Date object (this.dtModification)
	 */
	@Column( name = "dt_modification"  )
	public Date getDtModification() {
		return this.dtModification;
		
	}
	

  
    /**  
     * Set the value related to the column: dtModification.
	 * @param dtModification the dtModification value you wish to set
	 */
	public void setDtModification(final Date dtModification) {
		this.dtModification = dtModification;
	}

    /**
     * Return the value associated with the column: id.
	 * @return A Integer object (this.id)
	 */
    @Id 
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column( name = "id_mod_paie", nullable = false  )
	public Integer getId() {
		return this.id;
		
	}
	

  
    /**  
     * Set the value related to the column: id.
	 * @param id the id value you wish to set
	 */
	public void setId(final Integer id) {
		// If we've just been persisted and hashCode has been
		// returned then make sure other entities with this
		// ID return the already returned hash code
		if ( (this.id == null || this.id == 0) &&
				(id != null) &&
				(this.hashCode != null) ) {
			SAVED_HASHES.put( id, this.hashCode );
		}
		this.id = id;
	}

    /**
     * Return the value associated with the column: idCreationUser.
	 * @return A UserSystem object (this.idCreationUser)
	 */
	@ManyToOne( cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.LAZY )
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
	@JoinColumn(name = "Id_Creation_User", nullable = true )
	public UserSystem getIdCreationUser() {
		return this.idCreationUser;
		
	}
	

  
    /**  
     * Set the value related to the column: idCreationUser.
	 * @param idCreationUser the idCreationUser value you wish to set
	 */
	public void setIdCreationUser(final UserSystem idCreationUser) {
		this.idCreationUser = idCreationUser;
	}

    /**
     * Return the value associated with the column: idModificationUser.
	 * @return A UserSystem object (this.idModificationUser)
	 */
	@ManyToOne( cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.LAZY )
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
	@JoinColumn(name = "Id_Modification_User", nullable = true )
	public UserSystem getIdModificationUser() {
		return this.idModificationUser;
		
	}
	

  
    /**  
     * Set the value related to the column: idModificationUser.
	 * @param idModificationUser the idModificationUser value you wish to set
	 */
	public void setIdModificationUser(final UserSystem idModificationUser) {
		this.idModificationUser = idModificationUser;
	}

    /**
     * Return the value associated with the column: idService.
	 * @return A Service object (this.idService)
	 */
	@OneToOne ( fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST, CascadeType.MERGE } )
	@JoinColumn(name = "Id_Service",nullable=true)
	public Service getIdService() {
		return this.idService;
		
	}
	

  
    /**  
     * Set the value related to the column: idService.
	 * @param idService the idService value you wish to set
	 */
	public void setIdService(final Service idService) {
		this.idService = idService;
	}

    /**
     * Return the value associated with the column: modeleParametre.
	 * @return A Set&lt;ModeleParametre&gt; object (this.modeleParametre)
	 */
 	@OneToMany( fetch = FetchType.EAGER, cascade = {CascadeType.ALL}, mappedBy = "idModPaie"  )
 	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
	@Column( name = "id_mod_paie", nullable = false  )
	public Set<ModeleParametre> getModeleParametre() {
		return this.modeleParametre;
		
	}
	
	/**
	 * Adds a bi-directional link of type ModeleParametre to the modeleParametre set.
	 * @param modeleParametre item to add
	 */
	public void addModeleParametre(ModeleParametre modeleParametre) {
		modeleParametre.setIdModPaie(this);
		this.modeleParametre.add(modeleParametre);
	}

  
    /**  
     * Set the value related to the column: modeleParametre.
	 * @param modeleParametre the modeleParametre value you wish to set
	 */
	public void setModeleParametre(final Set<ModeleParametre> modeleParametre) {
		this.modeleParametre = modeleParametre;
	}

    /**
     * Return the value associated with the column: nom.
	 * @return A String object (this.nom)
	 */
	@Column( length = 16777215  )
	public String getNom() {
		return this.nom;
		
	}
	/**  
     * Set the value related to the column: nom.
	 * @param nom the nom value you wish to set
	 */
	public void setNom(final String nom) {
		this.nom = nom;
	}
	/**
     * Return the value associated with the column: prix.
	 * @return A Double object (this.prix)
	 */
	public Double getPrix() {
		return this.prix;
		
	}
	

  
    /**  
     * Set the value related to the column: prix.
	 * @param prix the prix value you wish to set
	 */
	public void setPrix(final Double prix) {
		this.prix = prix;
	}

    /**
     * Return the value associated with the column: tva.
	 * @return A Double object (this.tva)
	 */
	public Double getTva() {
		return this.tva;
		
	}
	

  
    /**  
     * Set the value related to the column: tva.
	 * @param tva the tva value you wish to set
	 */
	public void setTva(final Double tva) {
		this.tva = tva;
	}


   /**
    * Deep copy.
	* @return cloned object
	* @throws CloneNotSupportedException on error
    */
    @Override
    public ModelePaiement clone() throws CloneNotSupportedException {
		
        final ModelePaiement copy = (ModelePaiement)super.clone();

		copy.setDateDebut(this.getDateDebut());
		copy.setDateFin(this.getDateFin());
		copy.setDescription(this.getDescription());
		copy.setDtCreation(this.getDtCreation());
		copy.setDtModification(this.getDtModification());
		copy.setId(this.getId());
		copy.setIdCreationUser(this.getIdCreationUser());
		copy.setIdModificationUser(this.getIdModificationUser());
		copy.setIdService(this.getIdService());
		if (this.getModeleParametre() != null) {
			copy.getModeleParametre().addAll(this.getModeleParametre());
		}
		copy.setNom(this.getNom());
		copy.setPrix(this.getPrix());
		copy.setTva(this.getTva());
		return copy;
	}
	


	/** Provides toString implementation.
	 * @see java.lang.Object#toString()
	 * @return String representation of this class.
	 */
	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();
		
		sb.append("dateDebut: " + this.getDateDebut() + ", ");
		sb.append("dateFin: " + this.getDateFin() + ", ");
		sb.append("description: " + this.getDescription() + ", ");
		sb.append("dtCreation: " + this.getDtCreation() + ", ");
		sb.append("dtModification: " + this.getDtModification() + ", ");
		sb.append("id: " + this.getId() + ", ");
		sb.append("nom: " + this.getNom() + ", ");
		sb.append("prix: " + this.getPrix() + ", ");
		sb.append("tva: " + this.getTva());
		return sb.toString();		
	}


	/** Equals implementation. 
	 * @see java.lang.Object#equals(java.lang.Object)
	 * @param aThat Object to compare with
	 * @return true/false
	 */
	@Override
	public boolean equals(final Object aThat) {
		Object proxyThat = aThat;
		
		if ( this == aThat ) {
			 return true;
		}

		
		if (aThat instanceof HibernateProxy) {
 			// narrow down the proxy to the class we are dealing with.
 			try {
				proxyThat = ((HibernateProxy) aThat).getHibernateLazyInitializer().getImplementation(); 
			} catch (org.hibernate.ObjectNotFoundException e) {
				return false;
		   	}
		}
		if (aThat == null)  {
			 return false;
		}
		
		final ModelePaiement that; 
		try {
			that = (ModelePaiement) proxyThat;
			if ( !(that.getClassType().equals(this.getClassType()))){
				return false;
			}
		} catch (org.hibernate.ObjectNotFoundException e) {
				return false;
		} catch (ClassCastException e) {
				return false;
		}
		
		
		boolean result = true;
		result = result && (((this.getId() == null) && ( that.getId() == null)) || (this.getId() != null  && this.getId().equals(that.getId())));
		result = result && (((getDateDebut() == null) && (that.getDateDebut() == null)) || (getDateDebut() != null && getDateDebut().equals(that.getDateDebut())));
		result = result && (((getDateFin() == null) && (that.getDateFin() == null)) || (getDateFin() != null && getDateFin().equals(that.getDateFin())));
		result = result && (((getDescription() == null) && (that.getDescription() == null)) || (getDescription() != null && getDescription().equals(that.getDescription())));
		result = result && (((getDtCreation() == null) && (that.getDtCreation() == null)) || (getDtCreation() != null && getDtCreation().equals(that.getDtCreation())));
		result = result && (((getDtModification() == null) && (that.getDtModification() == null)) || (getDtModification() != null && getDtModification().equals(that.getDtModification())));
		result = result && (((getIdCreationUser() == null) && (that.getIdCreationUser() == null)) || (getIdCreationUser() != null && getIdCreationUser().getId().equals(that.getIdCreationUser().getId())));	
		result = result && (((getIdModificationUser() == null) && (that.getIdModificationUser() == null)) || (getIdModificationUser() != null && getIdModificationUser().getId().equals(that.getIdModificationUser().getId())));	
		result = result && (((getIdService() == null) && (that.getIdService() == null)) || (getIdService() != null && getIdService().equals(that.getIdService())));
		result = result && (((getNom() == null) && (that.getNom() == null)) || (getNom() != null && getNom().equals(that.getNom())));
		result = result && (((getPrix() == null) && (that.getPrix() == null)) || (getPrix() != null && getPrix().equals(that.getPrix())));
		result = result && (((getTva() == null) && (that.getTva() == null)) || (getTva() != null && getTva().equals(that.getTva())));
		return result;
	}
	
	/** Calculate the hashcode.
	 * @see java.lang.Object#hashCode()
	 * @return a calculated number
	 */
	@Override
	public int hashCode() {
		if ( this.hashCode == null ) {
			synchronized ( this ) {
				if ( this.hashCode == null ) {
					Integer newHashCode = null;

					if ( getId() != null ) {
						newHashCode = SAVED_HASHES.get( getId() );
					}
					
					if ( newHashCode == null ) {
						if ( getId() != null && getId() != 0) {
							newHashCode = getId();
						} else {
							newHashCode = super.hashCode();

						}
					}
					
					this.hashCode = newHashCode;
				}
			}
		}
	return this.hashCode;
	}
	

	
}
